
<?php
// array for JSON response
$response = array();
include("conn.php");
// check for required fields
if (isset($_POST['username']) && isset($_POST['lon']) &&isset($_POST['lat'])&& isset($_POST['time'])&& isset($_POST['note'])) {
    
    $name = $_POST['username'];
    $lon = $_POST['lon'];
    $lat = $_POST['lat'];
    $time = $_POST['time'];
    $note = $_POST['note'];
    $result = mysql_query("INSERT INTO mydb(username, lon, lat,time,note) VALUES('$username', '$lon', '$lat', '$time','$note')");// check if row inserted or not
    if ($result) {
        // successfully inserted into database
        $response["success"] = 1;
        $response["message"] = "Product successfully created.";

        // echoing JSON response
        echo json_encode($response);
    } else {
        // failed to insert row
        $response["success"] = 0;
        $response["message"] = "Oops! An error occurred.";
        
        // echoing JSON response
        echo json_encode($response);
    }
} else {
    // required field is missing
    $response["success"] = 0;
    $response["message"] = "Required field(s) is missing";

    // echoing JSON response
    echo json_encode($response);
}
?>

